﻿using System;
using UltimateFracturing;
using UnityEngine;

// Token: 0x0200041D RID: 1053
public class UltimateFracturingFPS : MonoBehaviour
{
	// Token: 0x06001DD0 RID: 7632 RVA: 0x000B6F00 File Offset: 0x000B5100
	private void Start()
	{
		this.m_v3MousePosition = Input.mousePosition;
		this.m_bRaycastFound = false;
		this.m_fRecoilTimer = 0f;
		if (this.Weapon)
		{
			this.m_v3InitialWeaponPos = this.Weapon.localPosition;
			this.m_qInitialWeaponRot = this.Weapon.localRotation;
		}
	}

	// Token: 0x06001DD1 RID: 7633 RVA: 0x000B6F5C File Offset: 0x000B515C
	private void OnGUI()
	{
		Color color = GUI.color;
		if (this.ShootMode == UltimateFracturingFPS.Mode.ExplodeRaycast)
		{
			int num = Mathf.RoundToInt((float)Screen.width * this.HUDSize * 0.5f);
			Rect position = new Rect((float)(Screen.width / 2 - num), (float)(Screen.height / 2 - num), (float)(num * 2), (float)(num * 2));
			GUI.color = ((!this.m_bRaycastFound) ? this.HUDColorNormal : this.HUDColorRaycast);
			GUI.DrawTexture(position, this.HUDTexture, ScaleMode.StretchToFill, true);
			GUI.color = color;
		}
		GUI.color = color;
	}

	// Token: 0x06001DD2 RID: 7634 RVA: 0x000B6FF4 File Offset: 0x000B51F4
	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.W))
		{
			this.ShootMode = ((this.ShootMode != UltimateFracturingFPS.Mode.ExplodeRaycast) ? UltimateFracturingFPS.Mode.ExplodeRaycast : UltimateFracturingFPS.Mode.ShootObjects);
		}
		if (this.ObjectToShoot != null && this.ShootMode == UltimateFracturingFPS.Mode.ShootObjects)
		{
			if (this.Weapon)
			{
				this.Weapon.GetComponent<Renderer>().enabled = false;
			}
			if (Input.GetKeyDown(KeyCode.Space))
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.ObjectToShoot);
				gameObject.transform.position = base.transform.position;
				gameObject.transform.localScale = new Vector3(this.ObjectScale, this.ObjectScale, this.ObjectScale);
				gameObject.GetComponent<Rigidbody>().mass = this.ObjectMass;
				gameObject.GetComponent<Rigidbody>().solverIterations = 255;
				gameObject.GetComponent<Rigidbody>().AddForce(base.transform.forward * this.InitialObjectSpeed, ForceMode.VelocityChange);
				DieTimer dieTimer = gameObject.AddComponent<DieTimer>();
				dieTimer.SecondsToDie = this.ObjectLife;
			}
		}
		if (this.ShootMode == UltimateFracturingFPS.Mode.ExplodeRaycast)
		{
			if (this.Weapon)
			{
				this.Weapon.GetComponent<Renderer>().enabled = true;
			}
			bool keyDown = Input.GetKeyDown(KeyCode.Space);
			if (keyDown)
			{
				this.m_fRecoilTimer = this.RecoilDuration;
				if (this.AudioWeaponShot)
				{
					AudioSource.PlayClipAtPoint(this.AudioWeaponShot, base.transform.position, this.WeaponShotVolume);
				}
			}
			this.m_bRaycastFound = false;
			RaycastHit raycastHit;
			FracturedChunk fracturedChunk = FracturedChunk.ChunkRaycast(base.transform.position, base.transform.forward, out raycastHit);
			if (fracturedChunk)
			{
				this.m_bRaycastFound = true;
				if (keyDown)
				{
					fracturedChunk.Impact(raycastHit.point, this.ExplosionForce, this.ExplosionRadius, true);
				}
			}
		}
		if (this.m_fRecoilTimer > 0f)
		{
			if (this.Weapon)
			{
				this.Weapon.transform.localPosition = this.m_v3InitialWeaponPos + new Vector3(0f, 0f, -this.m_fRecoilTimer / this.RecoilDuration * this.RecoilIntensity);
				this.Weapon.transform.localRotation = this.m_qInitialWeaponRot * Quaternion.Euler(new Vector3(this.m_fRecoilTimer / this.RecoilDuration * 360f * this.RecoilIntensity * 0.1f, 0f, 0f));
			}
			this.m_fRecoilTimer -= Time.deltaTime;
		}
		else if (this.Weapon)
		{
			this.Weapon.transform.localPosition = this.m_v3InitialWeaponPos;
			this.Weapon.transform.localRotation = this.m_qInitialWeaponRot;
		}
		if (Input.GetMouseButton(0) && !Input.GetMouseButtonDown(0))
		{
			base.transform.Rotate(-(Input.mousePosition.y - this.m_v3MousePosition.y) * this.MouseSpeed, 0f, 0f);
			base.transform.RotateAround(base.transform.position, Vector3.up, (Input.mousePosition.x - this.m_v3MousePosition.x) * this.MouseSpeed);
		}
		this.m_v3MousePosition = Input.mousePosition;
	}

	// Token: 0x04001DE6 RID: 7654
	public UltimateFracturingFPS.Mode ShootMode = UltimateFracturingFPS.Mode.ExplodeRaycast;

	// Token: 0x04001DE7 RID: 7655
	public float MouseSpeed = 0.3f;

	// Token: 0x04001DE8 RID: 7656
	public Texture HUDTexture;

	// Token: 0x04001DE9 RID: 7657
	public float HUDSize = 0.03f;

	// Token: 0x04001DEA RID: 7658
	public Color HUDColorNormal;

	// Token: 0x04001DEB RID: 7659
	public Color HUDColorRaycast;

	// Token: 0x04001DEC RID: 7660
	public Transform Weapon;

	// Token: 0x04001DED RID: 7661
	public AudioClip AudioWeaponShot;

	// Token: 0x04001DEE RID: 7662
	public float WeaponShotVolume = 1f;

	// Token: 0x04001DEF RID: 7663
	public float ExplosionForce = 1f;

	// Token: 0x04001DF0 RID: 7664
	public float ExplosionRadius = 0.4f;

	// Token: 0x04001DF1 RID: 7665
	public float RecoilDuration = 0.2f;

	// Token: 0x04001DF2 RID: 7666
	public float RecoilIntensity = 0.05f;

	// Token: 0x04001DF3 RID: 7667
	public GameObject ObjectToShoot;

	// Token: 0x04001DF4 RID: 7668
	public float InitialObjectSpeed = 1f;

	// Token: 0x04001DF5 RID: 7669
	public float ObjectScale = 1f;

	// Token: 0x04001DF6 RID: 7670
	public float ObjectMass = 1f;

	// Token: 0x04001DF7 RID: 7671
	public float ObjectLife = 10f;

	// Token: 0x04001DF8 RID: 7672
	private Vector3 m_v3MousePosition;

	// Token: 0x04001DF9 RID: 7673
	private bool m_bRaycastFound;

	// Token: 0x04001DFA RID: 7674
	private float m_fRecoilTimer;

	// Token: 0x04001DFB RID: 7675
	private Vector3 m_v3InitialWeaponPos;

	// Token: 0x04001DFC RID: 7676
	private Quaternion m_qInitialWeaponRot;

	// Token: 0x0200041E RID: 1054
	public enum Mode
	{
		// Token: 0x04001DFE RID: 7678
		ShootObjects,
		// Token: 0x04001DFF RID: 7679
		ExplodeRaycast
	}
}
